﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace _03.装饰者模式
{
    public class ProductDecorator : Product
    {

        protected ProductDecorator()
        {
            this.DecorativeProducts = new HashSet<Product>();
        }

        public ProductDecorator(string productName, Product mainProduct, decimal discountScale, params Product[] decorativeProducts)
            : this()
        {
            base.ProductName = productName;

            this.MainProduct = mainProduct;
            Array.ForEach(decorativeProducts, x => this.DecorativeProducts.Add(x));

            base.Price = this.CaculatePrice(discountScale);
        }

        public virtual Product MainProduct { get; private set; }
        public virtual ICollection<Product> DecorativeProducts { get; private set; }

        private decimal CaculatePrice(decimal discountScale)
        {
            decimal decorativeAmount = this.DecorativeProducts.Sum(x => x.Price) * discountScale;
            return this.MainProduct.Price + decorativeAmount;
        }
    }
}
